<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="客户" prop="custom">
        <el-input v-model.trim="queryParams.custom" @input="onInputChange1($event)" placeholder="请输入客户" clearable
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="机型" prop="model">
        <el-input v-model.trim="queryParams.model" @input="onInputChange2($event)" placeholder="请输入机型" clearable
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="项目编码" prop="projectNo">
        <el-input v-model.trim="queryParams.projectNo" @input="onInputChange8" placeholder="请输入项目编码" clearable
          @keyup.enter.native="handleQuery" />
      </el-form-item>

      <el-form-item label="芯片组" prop="chipGroup">
        <el-input v-model.trim="queryParams.chipGroup" @input="onInputChange3($event)" placeholder="请输入芯片组" clearable
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="AD板" prop="adBoard">
        <el-input v-model.trim="queryParams.adBoard" @input="onInputChange4($event)" placeholder="请输入芯片组" clearable
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="LCM/OC" prop="lcmOc">
        <el-input v-model.trim="queryParams.lcmOc" @input="onInputChange5($event)" placeholder="请输入LCM/OC" clearable
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="电源/适配器" class="labelword" prop="powerSupply">
        <el-input v-model.trim="queryParams.powerSupply" @input="onInputChange0($event)" placeholder="请输入电源/适配器"
          clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="ARM板" prop="armBoard">
        <el-input v-model.trim="queryParams.armBoard" @input="onInputChange6($event)" placeholder="请输入ARM板" clearable
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="恒流板" prop="currentBoard">
        <el-input v-model.trim="queryParams.currentBoard" @input="onInputChange7($event)" placeholder="请输入恒流板" clearable
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="其他" prop="other">
        <el-input v-model.trim="queryParams.other" @input="onInputChange9($event)" placeholder="请输入其他" clearable
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="项目状态">
        <el-select @change="selectChange($event)" v-model="queryParams.status" placeholder="请选择项目状态" clearable>
          <el-option v-for="dict in dict.type.project_status" :key="dict.value" :label="dict.label"
            :value="dict.value" />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>


    <el-row>
      <el-col :span="24">
        <el-button type="primary" plain  size="small" icon="el-icon-plus" @click="handleAdd()"  v-hasPermi="['business:project:add']"  >创建项目</el-button>

        <el-button type="warning" plain icon="el-icon-download"  size="small"   @click="handleExport"
          v-hasPermi="['business:project:export']">导出</el-button>
    
        <el-button type="success"   @click="handleImport"  size="small" 
          v-hasPermi="['business:project:import']">导入项目及历史bug</el-button>
        <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
      </el-col>
    </el-row>
    

    <el-table border v-loading="loading" :data="projectList" ref="projectTable" @selection-change="handleSelectionChange"
      :row-class-name="tableRowClassName" :row-key="getRowKey">
      <el-table-column type="selection" width="55" align="center" :reserve-selection="true" />
      <el-table-column label="客户" align="center" prop="custom"  width="120"></el-table-column>
      <el-table-column label="项目编码" align="left" width="120" prop="projectNo">
        <template slot-scope="scope">
          <router-link :to="{ name: `projectBugs`, query: { 'id': scope.row.id } }" class="link-type">
            
            {{ scope.row.projectNo }}
          </router-link>
        </template>
      </el-table-column>
      <el-table-column label="机型" width="120" align="center" prop="model" />
      <el-table-column label="项目经理" align="center" width="100" prop="pjManage" />
      <el-table-column label="AD板" align="center" prop="adBoard" width="100"/>
      <el-table-column label="芯片组" align="center" prop="chipGroup" width="100"/>
      <el-table-column label="LCM/OC" align="center" prop="lcmOc" />
      <el-table-column label="电源/适配器" align="center" prop="powerSupply" />
      <el-table-column label="状态" :show-overflow-tooltip="true" align="center" prop="status"  width="100"> 
        <template slot-scope="scope">
          <dict-tag :options="dict.type.project_status" :value="scope.row.status" />
        </template>
      </el-table-column>
      <el-table-column label="创建时间" align="center" prop="addTime"  width="120">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.addTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="创建人" align="center" prop="addUserTxt"  width="100"/>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" fixed="right" width="120">
        <template slot-scope="scope">
          <el-button size="mini" type="text" v-show="scope.row.status != 20 && scope.row.status != 30"
            icon="el-icon-edit" @click="handleUpdate(scope.row)" v-hasPermi="['business:project:update']">修改</el-button>
          <el-button size="mini" type="text" v-show="scope.row.status != 20 && scope.row.status != 30"
            icon="el-icon-circle-close" @click="handleCancel(scope.row)"
            v-hasPermi="['business:project:cancel']">取消</el-button>
          <!-- <el-button size="mini" type="text" v-show="scope.row.status != 20" @click="handleDel(scope.row)"  icon="el-icon-delete"
            v-hasPermi="['business:project:delete']">删除</el-button> -->
          <el-button size="mini" type="text" @click="closeProject(scope.row)"
            v-show="scope.row.status != 20 && scope.row.status != 30"  icon="el-icon-switch-button" 
            v-hasPermi="['business:project:close']">关闭</el-button>
          <el-button size="mini" type="text" @click="openProject(scope.row)" v-show="scope.row.status == 20"
            v-hasPermi="['business:project:open']">Open</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />

    <!-- 新增/修改弹窗 -->
    <ProjectForm ref="ProjectForm" @close="closeOpen" @updateList="getList" :open="open" :title="title"
      :isUpdate="update">
    </ProjectForm>

    <!-- 导入项目bugList弹窗 -->
    <importFileLog ref="importFileLog" :templateFileKey="`project_bugList_template`"
      :urlName="`/business/project/import`" @updateList="getList()" />
  </div>
</template>

<script>
import ProjectForm from "@/components/business/project/projectForm";
import importFileLog from "@/components/importFileLog/index"
import { getProjectList, addProject, updateProject, getProjectDetail, delProject, close, cancel, openCloseProject } from "@/api/business/project";
export default {
  name: "Project",
  components: { ProjectForm, importFileLog },
  dicts: ['project_status'],
  data() {
    return {
      update: false,
      // 遮罩层
      loading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 打样表格数据
      projectList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        custom: null,
        model: null,
        chipGroup: null,
        lcmOc: null,
        adBoard: null,
        powerSupply: null,
        armBoard: null,
        currentBoard: null,
        projectNo: null,
        other: null,
        status: null,
        ids: [],
        exportFlag: null
      },
    };
  },
  created() {
    this.getList()
  },
  methods: {
    //回显id
    getRowKey(row) {
      return row.id
    },
    //打开已关闭的项目
    openProject(row) {
      this.$modal.confirm('是否确认重新打开项目编号为"' + row.projectNo + '"的数据项？').then(function () {
        return openCloseProject(row.id);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("打开成功");
      }).catch(() => { });
    },
    //导入项目以及对应的bug
    handleImport() {
      this.$refs.importFileLog.onOpen()
    },
    closeOpen() {
      this.open = false
    },
    changeStatus(event) {
      this.queryParams.status = event
      this.getList()
    },
    tableRowClassName({ row, rowIndex }) {
      if (row.status == -1) {
        return 'danger-row'
      } else if (row.status == 5) {
        return 'success-row'
      }
      return ''
    },
    /** 查询项目列表 */
    getList() {
      this.queryParams.exportFlag=null
      this.loading = true;
      getProjectList(this.queryParams).then(response => {
        this.projectList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    onInputChange0(event) {
      this.queryParams.powerSupply = event
      this.getList()
    },
    onInputChange1(event) {
      this.queryParams.custom = event
      this.getList()
    },
    onInputChange2(event) {
      // console.log(event)
      this.queryParams.model = event
      this.getList()
    },
    onInputChange3(event) {
      this.queryParams.chipGroup = event
      this.getList()
    },
    onInputChange4(event) {
      this.queryParams.adBoard = event
      this.getList()
    },
    onInputChange5(event) {
      this.queryParams.lcmOc = event
      this.getList()
    },
    onInputChange6(event) {
      this.queryParams.armBoard = event
      this.getList()
    },
    onInputChange7(event) {
      this.queryParams.currentBoard = event
      this.getList()
    },
    onInputChange8(event) {
      this.queryParams.projectNo = event
      this.getList()
    },
    onInputChange9(event) {
      this.queryParams.other = event
      this.getList()
    },
    selectChange(event) {
      this.queryParams.status = event
      this.getList()
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.queryParams.ids = selection.map(item => item.id) 
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.update = false
      this.open = true
      this.title = "新增项目数据"
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.open = true
      this.title = "修改项目数据"
      this.update = true
      this.$refs.ProjectForm.getProjectBYId(row.id);
    },
    /** 删除按钮操作 */
    handleCancel(row) {
      const ids = row.id //|| this.ids;
      this.$modal.confirm('是否确认取消项目编号为"' + row.projectNo + '"的数据项？').then(function () {
        return cancel(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("取消成功");
      }).catch(() => { });
    },
    /** 删除按钮操作 */
    handleDel(row) {
      const ids = row.id //|| this.ids;
      this.$modal.confirm('是否确认删除项目编号为"' + row.projectNo + '"的数据项？').then(function () {
        return delProject(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => { });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.queryParams.exportFlag="1"
      this.download('/business/project/export', {
        ...this.queryParams
      }, `${new Date().getTime()}_项目数据.xlsx`)
      //清除多选数据
      this.$refs.projectTable.clearSelection();
    },
    // 关闭项目
    closeProject(row) {
      const ids = row.id;
      this.$modal.confirm('是否确认关闭项目编号为"' + row.projectNo + '"的数据项？').then(function () {
        return close(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("关闭成功");
      }).catch(() => { });
    }
  }
};
</script>
<style scoped>
.el-col {
  height: 60px;
}

.labelword ::v-deep .el-form-item__label {
  white-space: pre-line !important;
  line-height: 15px !important;
}

.el-table .danger-row {
  background: rgb(187, 179, 184);
}

.el-table .success-row {
  background: #00FF00;
}
</style>
